package com.kayt.cyberBar.cuser.business.dao.impl;

import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.dao.EntityDao;
import com.kayt.cyberBar.cuser.business.dao.ISheetStoreFutureWorkDao;
import com.kayt.cyberBar.cuser.business.entity.po.BSheetStoreFutureWork;

@Repository("sheetStoreFutureWorkDao")
public class SheetStoreFutureWorkDaoImpl implements ISheetStoreFutureWorkDao {
	@Autowired
	private EntityDao entityDao;
	@Override
	public Integer save(BSheetStoreFutureWork entity) throws SQLException {
			if(entity != null){
				entityDao.save(entity);
				return 0;
			}else{
				return -1;
			}
	}

	@Override
	public Integer update(BSheetStoreFutureWork entity) throws SQLException {
		
			if(entity != null){
				entityDao.update(entity);
				return 0;
			}else{
				return -1;
			}
	}

	@Override
	public Integer delete(Integer id) {
		
			if(id != null){
				BSheetStoreFutureWork BSheetStoreFutureWork = findById(id);
				if(BSheetStoreFutureWork != null){
					entityDao.delete(BSheetStoreFutureWork);
					return 0;
				}else{
					return -1;
				}
			}else{
				return -1;
			}
	}

	@Override
	public BSheetStoreFutureWork findById(Integer id) {
		
			if(id != null){
				return entityDao.findById(id, BSheetStoreFutureWork.class);
			}else{
				return null;
			}
	}

	@Override
	public PageData<BSheetStoreFutureWork> findByPage(int pageNum, int pageSize, String hql, Object[] params,
			LinkedHashMap<String, String> orderMap) throws SQLException {
		return this.entityDao.getPagingData(BSheetStoreFutureWork.class, pageNum, pageSize, hql, params, orderMap);
	}

	@Override
	public BSheetStoreFutureWork findBSheetStoreFutureWork(String workCode, String shiftCode, String date)
			throws SQLException {
		String sql = "select * from b_sheet_store_future_work where WORK_CODE = '" + workCode + "' and SHIFT_CODE = '"
				+ shiftCode + "' and WORK_TIME = '" + date + "'";
		List<BSheetStoreFutureWork> futureWorkList = entityDao.getPagingDataBySql(BSheetStoreFutureWork.class, -1, -1, sql, null);
		if(futureWorkList != null && futureWorkList.size() != 0){
			return futureWorkList.get(0);
		}else{
			return null;
		}
	}

	@Override
	public void remove(BSheetStoreFutureWork entity) {
		entityDao.delete(entity);
	}

	@Override
	public void batchDelete(List<BSheetStoreFutureWork> entityList) {
		entityDao.batchDelete(entityList);
	}
}
